<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="format-detection" content="telephone=no">
        <title>申请查询</title>

        <link rel="stylesheet" href="/Manage/css/frozen.css">
        <link rel="stylesheet" href="/Manage/css/demo.css">
        <style type="text/css">
            .ui-list-text li{padding-top: 5px; padding-bottom: 5px;}
            
            .search{position: fixed; top: 0px; left: 0px; width:100%; z-index: 10}

            .list{margin-bottom: 10px; padding-top: 45px;}
            .list .item{border-bottom: #f8f8f8 5px solid; margin-bottom: 0px;}
            .list .item .headblank{border-bottom: #f8f8f8 1px dashed;}
            .list .item .userblank{font-size: 12px;}
            .waiting{
                border-bottom: transparent 45px solid;
                line-height: 30px;
                text-align: center;
                font-size: 14px;
            }
            #s1-goTopBtn{
                position: fixed;
                text-align: center;
                line-height: 30px;
                width: 30px;
                font-size: 28px;
                height: 30px;
                right: 10px;
                right: 10px;
                cursor: pointer;
                _position: absolute;
                _right: auto;
                bottom: 85px;
                color: #18b4ed;
                z-index: 100;
                display: none;
                color: #fff;
                font-weight: 500;
                z-index: 100;
                background-color: #18b4ed;
                padding: 5px;
                border-radius: 5px;
            }

            .control label{display: block; font-size: 12px; padding: 2px 5px; color: #333; margin: 8px 0px;}
            .control label.no{background-color: #f75549; color: #fff;}
            .control label.yes{background-color: #429842; color: #fff;}
        </style>

    </head>
    
    <body ontouchstart>
        <!-- <header class="ui-header ui-header-positive ui-border-b">
            <i class="ui-icon-return" onclick="history.back()"></i><h1>搜索框 searchbar</h1><button class="ui-btn">回首页</button>
        </header> -->
        
        <section class="ui-container">

        <section id="searchbar">
            <div class="demo-item">
       
                    <div  class="ui-searchbar-wrap ui-border-b search">
                        <div class="ui-searchbar ui-border-radius">
                            <i class="ui-icon-search"></i>
                            <div class="ui-searchbar-text">单号/货名/手机号/备注/用户名/ID</div>
                            <div class="ui-searchbar-input">
                            <form action="" class="input-kw-form">
                                <input type="search" id="keyword" autocomplete="off" placeholder="单号/货名/手机号/备注/用户名/ID" autocapitalize="off">
                            </form>
                            </div>
                            <i class="ui-icon-close"></i>
                        </div>
                        <button class="ui-searchbar-cancel">取消</button>
                    </div>
                    <div class="demo-item">
                        <div class="demo-block list" id="id-applylist">
                            

                            <script id="test" type="text/html">
                            
                            <% for (x in list) { %>
                            <ul class="ui-list ui-list-text item" >
                                <li class="headblank">
                                    <div class="ui-list-info">
                                        <h4>申请id:<%=list[x].apply_id%></h4>
                                    </div>
                                    <div class="ui-badge-muted"><%=list[x].apply_time%></div>
                                </li>
                                <li>
                                    <a class="ui-avatar" href="<%=list[x].goods_image%>">
                                        <span style="background-image:url(<%=list[x].goods_image%>)"></span>
                                    </a>
                                    <div class="ui-list-info">
                                        <h4 class="ui-nowrap"><%=list[x].goods_name%></h4>
                                        <p class="ui-nowrap"><%=list[x].goods_quan%> × <%=list[x].goods_num%><%=list[x].goods_unit%>(共 <b><%=list[x].goods_quan * list[x].goods_num%></b> 券)</p>
                                    </div>
                                    <div class="ui-txt-info control" data-id="<%=list[x].apply_id%>">
                                        <%if(list[x].apply_state==2){ %>
                                            <label>已拒绝</label>
                                        <%}else if(list[x].apply_state==70){%>
                                            <label>已超期</label>
                                        <%}else if(list[x].apply_state==1){ %>
                                            <label>审核通过</label>
                                        <%}else if(list[x].apply_state==6){%>
                                            <label>已拒收</label>
                                        <%}else if(list[x].apply_state==0){ %>
                                            <label class="fun-shenhe no" data-flag="2">拒绝</label>
                                            <label class="fun-shenhe yes" data-flag="1">通过</label>
                                        <%}else if(list[x].apply_state==3){ %>
                                            <label>已发货</label>
                                        <%}else if(list[x].apply_state==5){ %>
                                            <label>已收货</label>
                                        <%}else if(list[x].apply_state==70){ %>
                                            <label>已超期</label>
                                        <%}else if(list[x].apply_state==4){ %>
                                            <label>用户删除</label>
                                        <%}%>
                                    </div>
                                </li>
                                <li class="userblank">
                                    <div class="ui-list-info">
                                        <h4 class="ui-nowrap"><%=list[x].uid%>:<%=list[x].user_name%></h4>
                                    </div>
                                    <div class="ui-list-action"><%=list[x].user_mobile%></div>
                                </li>

                            </ul>
                            <%}%>
                            </script>   
                            
                        </div>
                        <div class="waiting" id='waiting'></div>
                    </div>
                    
               
            </div>
            <!-- 返回顶部 -->
            <div id="s1-goTopBtn" class="ui-icon-gototop"></div>
            <!-- 加载中 -->
            <div id="loading" class="ui-loading-block">
                <div class="ui-loading-cnt">
                    <i class="ui-loading-bright"></i>
                    <p>正在加载中...</p>
                </div>
            </div>
            <!-- 拒绝弹窗 -->
            <div class="ui-dialog">
                <div class="ui-dialog-cnt">
                    <div class="ui-dialog-bd">
                        <div>
   
                            <div class="ui-form-item ui-form-item-textarea" style="padding-left: 0px; padding-right: 0px; border: #e0e0e0 1px solid;">
                                <textarea placeholder="拒绝理由" style="padding-left: 0px; margin-top: 0px; padding: 5px; font-size: 14px;"></textarea>
                            </div>

                        </div>
                    </div>
                    <div class="ui-dialog-ft ui-btn-group">
                        <button type="button" data-role="button" class="select" id="dialogButton0">确认</button>
                        <button type="button" data-role="button" id="dialogButton1">取消</button>
                    </div>
                </div>
            </div>
            
        </section>


        </section><!-- /.ui-container-->
        <script type="text/javascript" src="/Manage/lib/jquery/1.9.1/jquery.min.js"></script> 
        <script type="text/javascript" src="/Manage/js/template-native.js"></script> 

                   
        <script type="text/javascript" src="/Manage/lib/layer/2.1/layer.js"></script>
        <script>
        var API_BASE='https://www.mayizhihuan.com';
        var API_APPLYLIST=API_BASE+'/Admin/apply';

        var page=1;
        var isEnd=false;
        var isLoading=false;
        var keyword="";
        // 判断滚动条停止时间
        var topValue = 0,// 上次滚动条到顶部的距离  
        interval = null;// 定时器

        // 判断登录
        function checkStatus(data){
            if(data.status=="0"){
                layer.msg(data.info, {icon:2,time:1000});
                if(data.info=="请先登录"){
                    window.parent.location.href="/Manage/mobile/login.html";
                } 
                return false;
            }
            return true;
        }
        // 搜索框
        $('.ui-searchbar').click(function(){
            $('.ui-searchbar-wrap').addClass('focus');
            $('.ui-searchbar-input input').focus();
        });
        $('.ui-searchbar-cancel').click(function(){
            $('.ui-searchbar-wrap').removeClass('focus');
        });
        // 读取列表
        function loadGoods(Obj){
            if (!isLoading){
                isLoading = true;
                page++;
                $.getJSON(API_APPLYLIST,Obj,function(data){
                    if(!checkStatus(data)) return;
                    total=data.total;
                    if(data.datas==''){
                        isEnd=true;
                        document.getElementById('waiting').innerHTML='全部加载完了';
                        return;
                    }else{
                        var data={'list':data.datas};
                        var html=template('test',data);
                        document.getElementById('id-applylist').innerHTML+=html;
                        isLoading=false;
                    } 
                });
            }
        }

        

        document.onscroll = function() {  
            if(interval == null)// 未发起时，启动定时器，1秒1执行  
                interval = setInterval("test()", 500);  
                topValue = document.documentElement.scrollTop;  
        } 
        function test() {  
            // 判断此刻到顶部的距离是否和1秒前的距离相等  
            if(document.documentElement.scrollTop == topValue) {  
                // console.log("scroll bar is stopping!"); 
                $("#s1-goTopBtn").removeClass("s1-goTopBtn-default");
                $("#s1-goTopBtn").addClass("ui-icon-gototop");
                $("#s1-goTopBtn").html(""); 
                clearInterval(interval);  
                interval = null;  
            }
        } 
        $(document).ready(function(){
            loadGoods({'p':page,'k':keyword});
            // 点击搜索事件
            $("#keyword").on('keypress',function(e) {  
                var keycode = e.keyCode;  
                keyword = $(this).val();  
                if(keycode=='13') {  
                    e.preventDefault();    
                    //请求搜索接口
                    document.getElementById('id-applylist').innerHTML=""; 
                    page=1;
                    isEnd=false;
                    isLoading=false; 
                    loadGoods({'p':page,'k':keyword});
                }  
            }); 
            // 清楚输入框内容
            $("i.ui-icon-close").on('click',function(e){
                $("#keyword").val("");
            })
            // 关闭弹出框
            $(document).on('click','#dialogButton1',function(){
                $(".ui-dialog").removeClass("show");
            })
            


            // 货物操作、审核/确认收货、拒收
            $(document).on('click','label.fun-shenhe',function(){
                var id=$(this).parent().data("id");
                var that=$(this);       
                var flag=that.data("flag");
    
                console.log(id);
                console.log(flag);
                if(flag==6 || flag==2){
                    // $(".ui-dialog").addClass("show");
                    // $(document).on('click','#dialogButton0',function(){
                    //     $.getJSON(API_APPLYLIST,{pass:id,state:flag},function(data){
                    //         if(!checkStatus(data)) return;
                    //         $(".ui-dialog").removeClass("show");
                    //     }); 
                    // })
                    layer.use('extend/layer.ext.js', function(){
                        layer.prompt({
                            title:'拒绝理由',
                        },function(val, index){
                            if($.trim(val)==""){
                                layer.msg('输入拒绝理由',{icon:2,time:1000});
                            }else{
                                $.getJSON(API_APPLYLIST,{pass:id,state:flag},function(data){
                                    if(!checkStatus(data)) return;
                                    // layer.msg(data.info,{icon:1,time:1000});
                                    $(".ui-dialog").removeClass("show");
                                    that.parent().html('已拒绝');
                                    layer.close(index);
                                });
                            }
                            
                        })
                    });
                    
                    
                }else if(flag==5){
                    layer.confirm('确认收货后,券将打到用户账户?',function(index){
                        $.getJSON(API_APPLYLIST,{pass:id,state:flag},function(data){
                            if(!checkStatus(data)) return;
                            that.parent().html('已确认收货');
                            layer.close(index);
                        })
                    })
                }else{
                    $.getJSON(API_APPLYLIST,{pass:id,state:flag},function(data){
                        if(!checkStatus(data)) return;
                        layer.msg(data.info,{icon:1,time:1000});
                        $(".ui-dialog").removeClass("show");
                        that.parent().html('已通过');

                    });  
                }
                
            })
            
            //onscroll
            window.onscroll=function(){
                var a =  window.screen.height;
                var b = document.documentElement.scrollTop!=0? document.documentElement.scrollTop: document.body.scrollTop;
                var c = document.documentElement.scrollTop!=0? document.documentElement.scrollHeight: document.body.scrollHeight;
                var d = 300;
                
                //回到顶部
                if(b>"0"){
                    dom_top.style.display='block';
                }else{
                    dom_top.style.display='none';
                }
                 
                if(a+b+d > c && !isEnd && !isLoading){
                    loadGoods({'p':page,'k':keyword});
                }

            }//onscroll

            //回到顶部
            var dom_top=document.getElementById('s1-goTopBtn');

            function getScrollTop() {  
                    return document.documentElement.scrollTop + document.body.scrollTop;  
                }  
            function setScrollTop(value) {  
                if (document.documentElement.scrollTop) {  
                    document.documentElement.scrollTop = value;  
                } else {  
                    document.body.scrollTop = value;  
                }  
            }  
            dom_top.onclick = function() {  
                var goTop = setInterval(scrollMove, 10);  
                function scrollMove() {  
                    setScrollTop(getScrollTop() / 1.1);  
                    if (getScrollTop() < 1) clearInterval(goTop);  
                }  
            }
        })
        </script>
    </body>
</html>